Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
usage-stats
Advanced tools
A minimal, offline-friendly Google Analytics Measurement Protocol client for tracking usage statistics in node.js apps.
A minimal, offline-friendly Google Analytics Measurement Protocol client for tracking usage statistics in node.js applications.
This is only a low-level client API, it doesn't hold any opinion of how usage tracking should be done. If you're looking for a convention which leverages the power and flexibility of Custom Metrics and Dimensions, take a look at track-usage.
The most trivial example.
const UsageStats = require('usage-stats')
const usageStats = new UsageStats('UA-98765432-1')
// track a hit on the 'main' screen with 'simple' mode set.
usageStats
.screenView('main')
.event('option', 'mode', 'simple')
.send()
More realistic usage in an example video encoding app.
const UsageStats = require('usage-stats')
const usageStats = new UsageStats('UA-98765432-1', {
name: 'enocode-video',
version: '1.0.0'
})
// start a new session
usageStats.start()
// user set two options..
usageStats.event('option', 'verbose-level', 'infinite')
usageStats.event('option', 'preset', 'iPod')
try {
// Begin. Track as a screenView.
usageStats.screenView('encoding')
beginEncoding(options)
} catch (err) {
// Exception tracking
usageStats.exception(err.message, true)
}
// finished - mark the session as complete
// and send stats (or store if offline).
usageStats.end().send()
See here for the full list of Google Analytics Measurement Protocol parameters.
All parameters are send on demand, beside this list.
process.env.LANG
, if set)Kind: inner class of UsageStats
Extends: usage-stats
Kind: instance method of UsageStatsAbortable
Overrides: send
Param | Type |
---|---|
[options] | object |
[options.timeout] | number |
Aborts the in-progress .send() operation, queuing any unsent hits.
Kind: instance method of UsageStatsAbortable
Chainable
Starts the session.
Kind: instance method of UsageStatsAbortable
Chainable
Param | Type | Description |
---|---|---|
[sessionParams] | Array.<Map> | An optional map of paramaters to send with each hit in the sesison. |
Ends the session.
Kind: instance method of UsageStatsAbortable
Chainable
Param | Type | Description |
---|---|---|
[sessionParams] | Array.<Map> | An optional map of paramaters to send with the final hit of this sesison. |
Disable the module. While disabled, all operations are no-ops.
Kind: instance method of UsageStatsAbortable
Chainable
Re-enable the module.
Kind: instance method of UsageStatsAbortable
Chainable
Map
Track an event. All event hits are queued until .send()
is called.
Kind: instance method of UsageStatsAbortable
Param | Type | Description |
---|---|---|
category | string | Event category (required). |
action | string | Event action (required). |
[options] | option | |
[options.label] | string | Event label |
[options.value] | string | Event value |
[options.hitParams] | Array.<map> | One or more additional params to send with the hit. |
Map
Track a screenview. All screenview hits are queued until .send()
is called. Returns the hit instance.
Kind: instance method of UsageStatsAbortable
Param | Type | Description |
---|---|---|
name | string | Screen name |
[options] | object | |
[options.hitParams] | Array.<map> | One or more additional params to set on the hit. |
Map
Track a exception. All exception hits are queued until .send()
is called.
Kind: instance method of UsageStatsAbortable
Param | Type | Description |
---|---|---|
description | string | Error message |
isFatal | boolean | Set true if the exception was fatal |
[options.hitParams] | Array.<map> | One or more additional params to set on the hit. |
Promise
Send any hits (including queued) to the GA validation server, fulfilling with the result.
Kind: instance method of UsageStatsAbortable
Fulfil: Response[]
Reject: Error
- Error instance includes hits
.
© 2016 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.
FAQs
A minimal, offline-friendly Google Analytics Measurement Protocol client for tracking statistics in shell and javascript applications
The npm package usage-stats receives a total of 2,218 weekly downloads. As such, usage-stats popularity was classified as popular.
We found that usage-stats demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.